package com.business.commons.baseUtil;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * 
 */
public class Map2Url {

	private Map2Url(){
	}
	
	
	private static Map2Url instance;
	
	public static Map2Url get() {
		if(instance == null ){
			instance = new Map2Url(); 
		}
		return instance;
	}
	
	/**
	 * 
	 * @param map
	 * @return key1=value1&key2=value2...
	 */
	public  String map2string(Map map) {

		if (null == map || map.isEmpty()) {
			return null;
		} else {
			StringBuilder stringBuilder = new StringBuilder();
			Iterator iterator = map.keySet().iterator();
			while (iterator.hasNext()) {
				Object key = iterator.next();
				Object value = map.get(key);
				if (null != value && !(value instanceof Class)
						&& !(value instanceof List)) {
					stringBuilder.append(key).append("=").append(value).append(
							"&");
				}
			}

			return stringBuilder.deleteCharAt(stringBuilder.length() - 1)
					.toString();
		}
	}

	
}
